package com.showsu.editor.utils.remote;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.showsu.editor.entity.platform.xhs.AwemeDetailPlatformResult;
import com.showsu.editor.entity.platform.xhs.XhsAwemeDetailResult;
import com.showsu.editor.entity.remote.VideoDetailResult;
import com.showsu.editor.entity.remote.WhoseCardVideoDetailResp;
import com.showsu.editor.entity.remote.moreapi.DyAwemeDetailResult;
import com.showsu.editor.entity.remote.moreapi.XhsAwemeDetailMoreApiResult;
import com.showsu.editor.enums.SuccessEnum;
import com.showsu.editor.service.IRemoteInterfaceRecordService;
import com.showsu.editor.service.IRemoteInterfaceWarnSmsRecordService;
import com.showsu.editor.utils.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

/**
 * @Author: William
 * @Description: 自己部署的爬虫，目前用了moreapi的模式
 * @Date: Created in 9:15 下午 2024/8/22
 * @Modified By:
 */
@Slf4j
@Component
public class SelfAPIUtil {

    private static final int timeout = 20000;

    /**
     * 最多重试次数
     */
    private static final int RETRY_MAX_COUNT = 3;

    /**
     * 重试等待间隔
     */
    private static final int RETRY_WAIT_TIME = 1500;

    @Value("${selfAPI.url}")
    private String baseUrl;

    @Value("${selfAPI.token}")
    private String token;

    @Autowired
    private IRemoteInterfaceRecordService remoteInterfaceRecordService;

    @Autowired
    private IRemoteInterfaceWarnSmsRecordService remoteInterfaceWarnSmsRecordService;

    /**
     * gson反序列化时，用于忽略array的错误。因为有的时候字段返回为空，我们认为是可以接受的。
     */
    private GsonFailSafeArrayJsonDeserializer gsonFailSafeArrayJsonDeserializer = new GsonFailSafeArrayJsonDeserializer();

    /**
     * 获取dy作品详情
     * https://apifox.com/apidoc/shared-0b55c993-4634-4f70-b6fc-3edf1c27344d/api-127641556
     * @param awemeId 作品id
     * @return
     */
    public WhoseCardVideoDetailResp getDyAwemeDetail(String awemeId, Long interfaceId) {
        if (StringUtils.isBlank(awemeId)) {
            return null;
        }
        WhoseCardVideoDetailResp result = new WhoseCardVideoDetailResp();
        //请求参数准备
        Map<String, Object> params = new HashMap<>();
        params.put("aweme_id", awemeId);

        Map<String, String> headers = new HashMap<>();
        headers.put("Authorization", "Bearer " + token);

        String response = RetryUtils.retry(new Callable<String>() {
            @Override
            public String call() {
                try {
                    long start = System.currentTimeMillis();
                    String responseInner = HttpClientUtil.postByJson(baseUrl + "/api/douyin/aweme_detail", headers, JSON.toJSONString(params), timeout);
                    log.info("SelfAPIUtil查询dy作品详情数据-响应耗时:{}", System.currentTimeMillis() - start);
                    DyAwemeDetailResult temp = JSON.parseObject(responseInner, DyAwemeDetailResult.class);
                    //如果平台那边报错再重试一次
                    if (temp == null || (temp != null && temp.getCode() != null && temp.getCode().intValue() != 200)) {
                        remoteInterfaceRecordService.add(interfaceId, SuccessEnum.FAIL.getCode());
                        return "";
                    }
                    remoteInterfaceRecordService.add(interfaceId, SuccessEnum.SUCCESS.getCode());
                    return responseInner;
                } catch (Exception e) {
                    remoteInterfaceRecordService.add(interfaceId, SuccessEnum.FAIL.getCode());
                    log.error("SelfAPIUtil.getDyAwemeDetail(String, Long) error, awemeId:{}, interfaceId:{}, e:{}", awemeId, interfaceId, e);
                    return "";
                }
            }
        }, RETRY_MAX_COUNT, RETRY_WAIT_TIME);
        if (StringUtils.isBlank(response)) {
            remoteInterfaceWarnSmsRecordService.sendWarnSmsIn15mins(interfaceId,
                    new StringBuilder("awemeId=").append(awemeId).toString());
            return result;
        }
        try {
            DyAwemeDetailResult originResult = JSON.parseObject(response, DyAwemeDetailResult.class);
            VideoDetailResult videoDetailResult = new VideoDetailResult();
            if(originResult.getData()!=null){
                videoDetailResult.setAweme_detail(originResult.getData().getAweme_detail());
            }
            result.setResult(videoDetailResult);
        } catch (Exception e) {
            log.error("SelfAPIUtil.getDyAwemeDetail(String, Long) convert error, awemeId:{}, interfaceId:{}, e:{}", awemeId, interfaceId, e);
        }
        return result;
    }

    /**
     * 查询xhs笔记详情
     * http://doc.moreapi.wouldmissyou.com/api-181330818
     * @param noteId
     * @return
     */
    public XhsAwemeDetailResult getXhsAwemeDetail(String noteId, Long interfaceId) {
        if (StringUtils.isBlank(noteId)) {
            return null;
        }
        Type type = new TypeToken<XhsAwemeDetailMoreApiResult>(){}.getType();
        Gson gson = new GsonBuilder().registerTypeAdapter(List.class, gsonFailSafeArrayJsonDeserializer).create();

        Map<String, Object> params = new HashMap<>();
        params.put("note_id", noteId);
        //params.put("xsec_token", xSecToken);

        Map<String, String> headers = new HashMap<>();
        headers.put("Authorization", "Bearer " + token);

        String response = RetryUtils.retry(new Callable<String>() {
            @Override
            public String call() {
                try {
                    long start = System.currentTimeMillis();
                    String responseInner = HttpClientUtil.postByJson(baseUrl + "/api/xhs/note_detail", headers, JsonUtil.toJson(params), timeout);
                    log.info("SelfAPIUtil查询xhs作品详情-响应耗时:{}-noteId:{}", System.currentTimeMillis() - start, noteId);
                    JSONObject jsonObject = JSON.parseObject(responseInner);
                    if (jsonObject.get("data") == null) {
                        remoteInterfaceRecordService.add(interfaceId, SuccessEnum.FAIL.getCode());
                        return "";
                    }
                    JSONObject jsonObjectData = JSON.parseObject(jsonObject.getString("data"));
                    if (jsonObjectData.get("response_body") == null) {
                        remoteInterfaceRecordService.add(interfaceId, SuccessEnum.FAIL.getCode());
                        return "";
                    }
                    XhsAwemeDetailMoreApiResult temp = gson.fromJson(jsonObjectData.getString("response_body"), type);
                    if (temp != null
                            && (Constant.containsXhsAwemeNotExistHint(StringUtil.convertUnicodeToChinese(temp.getMsg()))
                            || (temp.getData() != null && Constant.containsXhsAwemeNotExistHint(StringUtil.convertUnicodeToChinese(temp.getData().getMsg())))
                    )
                    ){
                        remoteInterfaceRecordService.add(interfaceId, SuccessEnum.SUCCESS.getCode());
                        return Constant.xhsAwemeNotExist0;
                    }
                    //如果平台那边报错再重试一次
                    if (temp == null || (temp != null && temp.getCode() != null && temp.getCode().intValue() != 0)) {
                        remoteInterfaceRecordService.add(interfaceId, SuccessEnum.FAIL.getCode());
                        return "";
                    }
                    remoteInterfaceRecordService.add(interfaceId, SuccessEnum.SUCCESS.getCode());
                    return responseInner;
                } catch (Exception e) {
                    remoteInterfaceRecordService.add(interfaceId, SuccessEnum.FAIL.getCode());
                    log.error("SelfAPIUtil.getXhsAwemeDetail(String) error, noteId:{}, e:{}", noteId, e);
                    return "";
                }
            }
        }, RETRY_MAX_COUNT, RETRY_WAIT_TIME);
        if (StringUtils.isBlank(response)) {
            remoteInterfaceWarnSmsRecordService.sendWarnSmsIn15mins(interfaceId,
                    new StringBuilder("noteId=").append(noteId).toString());
            return null;
        }
        if (response.equals(Constant.xhsAwemeNotExist0)) {
            return null;
        }
        try {
            JSONObject jsonObject = JSON.parseObject(response);
            if (jsonObject.get("data") == null) {
                return null;
            }
            JSONObject jsonObjectData = JSON.parseObject(jsonObject.getString("data"));
            if (jsonObjectData.get("response_body") == null) {
                return null;
            }
            XhsAwemeDetailMoreApiResult xhsAwemeDetailMoreApiResultOrg = gson.fromJson(jsonObjectData.getString("response_body"), type);
            //对象转换
            if (xhsAwemeDetailMoreApiResultOrg != null && xhsAwemeDetailMoreApiResultOrg.getData() != null
                    && ! CollectionUtils.isEmpty(xhsAwemeDetailMoreApiResultOrg.getData().getItems())
                    && xhsAwemeDetailMoreApiResultOrg.getData().getItems().get(0).getNote_card() != null) {
                XhsAwemeDetailMoreApiResult.Note xhsAwemeDetailMoreApiResult = xhsAwemeDetailMoreApiResultOrg.getData().getItems().get(0).getNote_card();
                AwemeDetailPlatformResult awemeDetailPlatformResult = new AwemeDetailPlatformResult();
                AwemeDetailPlatformResult.AwemeDetail awemeDetail = awemeDetailPlatformResult.new AwemeDetail();
                //装载user对象
                AwemeDetailPlatformResult.AwemeDetail.User user = awemeDetail.new User();
                if (xhsAwemeDetailMoreApiResult.getUser() != null) {
                    user.setNickname(xhsAwemeDetailMoreApiResult.getUser().getNickname());
                    user.setImage(xhsAwemeDetailMoreApiResult.getUser().getAvatar());
                    user.setUserid(xhsAwemeDetailMoreApiResult.getUser().getUser_id());
                }
                awemeDetail.setUser(user);
                //装载笔记对象
                List<AwemeDetailPlatformResult.AwemeDetail.Note> noteList = new ArrayList<>();
                AwemeDetailPlatformResult.AwemeDetail.Note note = awemeDetail.new Note();
                note.setDesc(xhsAwemeDetailMoreApiResult.getDesc());
                note.setTitle(xhsAwemeDetailMoreApiResult.getTitle());
                note.setTime(xhsAwemeDetailMoreApiResult.getTime());
                note.setLast_update_time(xhsAwemeDetailMoreApiResult.getLast_update_time());
                note.setType(xhsAwemeDetailMoreApiResult.getType());
                note.setGoodsId(xhsAwemeDetailMoreApiResult.getGoodsId());
                note.setWidgets_context(xhsAwemeDetailMoreApiResult.getWidgets_context());
                if (xhsAwemeDetailMoreApiResult.getInteract_info() != null) {
                    note.setCollected(xhsAwemeDetailMoreApiResult.getInteract_info().getCollected());
                    note.setCollected_count(xhsAwemeDetailMoreApiResult.getInteract_info().getCollected_count());
                    note.setLiked_count(xhsAwemeDetailMoreApiResult.getInteract_info().getLiked_count());
                    note.setComments_count(xhsAwemeDetailMoreApiResult.getInteract_info().getComment_count());
                    note.setShared_count(xhsAwemeDetailMoreApiResult.getInteract_info().getShare_count());
                }

                AwemeDetailPlatformResult.AwemeDetail.Note.ShareInfo shareInfo = note.new ShareInfo();
                note.setShare_info(shareInfo);

                if (! CollectionUtils.isEmpty(xhsAwemeDetailMoreApiResult.getImage_list())) {
                    List<AwemeDetailPlatformResult.AwemeDetail.Note.Image> imageList = new ArrayList<>();
                    note.setImages_list(imageList);
                    shareInfo.setImage(xhsAwemeDetailMoreApiResult.getImage_list().get(0).getUrl_default());
                    for (XhsAwemeDetailMoreApiResult.Note.Image image : xhsAwemeDetailMoreApiResult.getImage_list()) {
                        AwemeDetailPlatformResult.AwemeDetail.Note.Image image1 = note.new Image();
                        image1.setFileid(image.getFile_id());
                        image1.setHeight(image.getHeight());
                        image1.setWidth(image.getWidth());
                        image1.setUrl(image.getUrl());
                        image1.setTrace_id(image.getTrace_id());
                        if(! CollectionUtils.isEmpty(image.getInfo_list())){
                            for(XhsAwemeDetailMoreApiResult.Note.Image.CoverInfo infoList : image.getInfo_list()){
                                if(Constant.CRD_WM_WEBP.equals(infoList.getImage_scene())){
                                    image1.setOriginal(infoList.getUrl());
                                }
                            }
                        }
                        if(image.getStream() != null && !CollectionUtils.isEmpty(image.getStream().getH264())){
                            AwemeDetailPlatformResult.AwemeDetail.Note.Image.LivePhoto livePhoto = image1.new LivePhoto();
                            AwemeDetailPlatformResult.AwemeDetail.Note.Image.LivePhoto.Media media = livePhoto.new Media();
                            AwemeDetailPlatformResult.AwemeDetail.Note.Image.LivePhoto.Media.Stream stream = media.new Stream();
                            List<AwemeDetailPlatformResult.AwemeDetail.Note.Image.LivePhoto.Media.Stream.H264> h264List = new ArrayList<>();
                            for (XhsAwemeDetailMoreApiResult.Note.Image.Stream.H264 h264 : image.getStream().getH264()) {
                                AwemeDetailPlatformResult.AwemeDetail.Note.Image.LivePhoto.Media.Stream.H264 h264_1 = stream.new H264();
                                h264_1.setMaster_url(h264.getMaster_url());
                                h264List.add(h264_1);
                            }
                            stream.setH264(h264List);
                            media.setStream(stream);
                            livePhoto.setMedia(media);
                            image1.setLive_photo(livePhoto);
                        }
                        imageList.add(image1);
                    }
                }

                //笔记文案
                if (StringUtils.isNotBlank(xhsAwemeDetailMoreApiResult.getTitle())) {
                    shareInfo.setTitle(xhsAwemeDetailMoreApiResult.getTitle());
                }
                //话题
                List<AwemeDetailPlatformResult.AwemeDetail.Note.HashTagDTO> hashTagDTOList=new ArrayList<>();
                for(XhsAwemeDetailMoreApiResult.Note.Tag tag :xhsAwemeDetailMoreApiResult.getTag_list()){
                    AwemeDetailPlatformResult.AwemeDetail.Note.HashTagDTO hashTag= new AwemeDetailPlatformResult().new AwemeDetail().new Note().new HashTagDTO();
                    hashTag.setId(tag.getId());
                    hashTag.setName(tag.getName());
                    hashTagDTOList.add(hashTag);
                }
                note.setHash_tag(hashTagDTOList);

                noteList.add(note);
                awemeDetail.setNote_list(noteList);
                awemeDetail.setUser(user);

                List<AwemeDetailPlatformResult.AwemeDetail> awemeDetailList = new ArrayList<>();
                awemeDetailList.add(awemeDetail);
                awemeDetailPlatformResult.setData(awemeDetailList);
                awemeDetailPlatformResult.setCode(xhsAwemeDetailMoreApiResultOrg.getCode());
                awemeDetailPlatformResult.setMsg(xhsAwemeDetailMoreApiResultOrg.getMsg());
                XhsAwemeDetailResult result = new XhsAwemeDetailResult();
                result.setData(awemeDetailPlatformResult);
                return null;
            }
        } catch (Exception e) {
            log.error("SelfAPIUtil.getXhsAwemeDetail(String) convert error, noteId:{}, e:{}", noteId, e);
        }
        return null;
    }

    /**
     * 查询xhs笔记详情V2
     * https://apifox.com/apidoc/shared-0b55c993-4634-4f70-b6fc-3edf1c27344d/api-198443110
     * @param noteId
     * @param xSecToken
     * @return
     */
    public XhsAwemeDetailResult getXhsAwemeDetail2(String noteId, String xSecToken, Long interfaceId) {
        if (StringUtils.isBlank(noteId) || StringUtils.isBlank(xSecToken)) {
            return null;
        }
        Type type = new TypeToken<XhsAwemeDetailMoreApiResult>(){}.getType();
        Gson gson = new GsonBuilder().registerTypeAdapter(List.class, gsonFailSafeArrayJsonDeserializer).create();
        XhsAwemeDetailResult result = new XhsAwemeDetailResult();

        Map<String, Object> params = new HashMap<>();
        params.put("note_id", noteId);
        params.put("xsec_token", xSecToken);

        Map<String, String> headers = new HashMap<>();
        headers.put("Authorization", "Bearer " + token);

        String response = RetryUtils.retry(new Callable<String>() {
            @Override
            public String call() {
                try {
                    long start = System.currentTimeMillis();
                    String responseInner = HttpClientUtil.postByJson(baseUrl + "/api/xhs/note_detail_v2", headers, JsonUtil.toJson(params), timeout);
                    log.info("SelfAPIUtil查询xhs作品详情V2-响应耗时:{}-noteId:{}", System.currentTimeMillis() - start, noteId);
                    XhsAwemeDetailMoreApiResult temp = gson.fromJson(responseInner, type);
                    if (temp != null && Constant.containsXhsAwemeNotExistHint(StringUtil.convertUnicodeToChinese(temp.getMsg()))) {
                        remoteInterfaceRecordService.add(interfaceId, SuccessEnum.SUCCESS.getCode());
                        return Constant.xhsAwemeNotExist0;
                    }
                    //如果平台那边报错再重试一次
                    if (temp == null || (temp != null && temp.getCode() != null && temp.getCode().intValue() != 200)) {
                        remoteInterfaceRecordService.add(interfaceId, SuccessEnum.FAIL.getCode());
                        return "";
                    }
                    remoteInterfaceRecordService.add(interfaceId, SuccessEnum.SUCCESS.getCode());
                    return responseInner;
                } catch (Exception e) {
                    remoteInterfaceRecordService.add(interfaceId, SuccessEnum.FAIL.getCode());
                    log.error("SelfAPIUtil.getXhsAwemeDetail2(String) error, noteId:{}, e:{}", noteId, e);
                    return "";
                }
            }
        }, RETRY_MAX_COUNT, RETRY_WAIT_TIME);
        if (StringUtils.isBlank(response)) {
            remoteInterfaceWarnSmsRecordService.sendWarnSmsIn15mins(interfaceId,
                    new StringBuilder("noteId=").append(noteId).toString());
            return result;
        }
        if (response.equals(Constant.xhsAwemeNotExist0)) {
            return null;
        }
        try {
            XhsAwemeDetailMoreApiResult xhsAwemeDetailMoreApiResultOrg = gson.fromJson(response, type);
            //对象转换
            if (xhsAwemeDetailMoreApiResultOrg != null && xhsAwemeDetailMoreApiResultOrg.getData() != null
                    && ! CollectionUtils.isEmpty(xhsAwemeDetailMoreApiResultOrg.getData().getItems())
                    && xhsAwemeDetailMoreApiResultOrg.getData().getItems().get(0).getNote_card() != null) {
                XhsAwemeDetailMoreApiResult.Note xhsAwemeDetailMoreApiResult = xhsAwemeDetailMoreApiResultOrg.getData().getItems().get(0).getNote_card();
                AwemeDetailPlatformResult awemeDetailPlatformResult = new AwemeDetailPlatformResult();
                AwemeDetailPlatformResult.AwemeDetail awemeDetail = awemeDetailPlatformResult.new AwemeDetail();
                //装载user对象
                AwemeDetailPlatformResult.AwemeDetail.User user = awemeDetail.new User();
                if (xhsAwemeDetailMoreApiResult.getUser() != null) {
                    user.setNickname(xhsAwemeDetailMoreApiResult.getUser().getNickname());
                    user.setImage(xhsAwemeDetailMoreApiResult.getUser().getAvatar());
                    user.setUserid(xhsAwemeDetailMoreApiResult.getUser().getUser_id());
                }
                awemeDetail.setUser(user);
                //装载笔记对象
                List<AwemeDetailPlatformResult.AwemeDetail.Note> noteList = new ArrayList<>();
                AwemeDetailPlatformResult.AwemeDetail.Note note = awemeDetail.new Note();
                note.setDesc(xhsAwemeDetailMoreApiResult.getDesc());
                note.setTitle(xhsAwemeDetailMoreApiResult.getTitle());
                note.setTime(xhsAwemeDetailMoreApiResult.getTime());
                note.setLast_update_time(xhsAwemeDetailMoreApiResult.getLast_update_time());
                note.setType(xhsAwemeDetailMoreApiResult.getType());
                note.setGoodsId(xhsAwemeDetailMoreApiResult.getGoodsId());
                note.setWidgets_context(xhsAwemeDetailMoreApiResult.getWidgets_context());
                if (xhsAwemeDetailMoreApiResult.getInteract_info() != null) {
                    note.setCollected(xhsAwemeDetailMoreApiResult.getInteract_info().getCollected());
                    note.setCollected_count(xhsAwemeDetailMoreApiResult.getInteract_info().getCollected_count());
                    note.setLiked_count(xhsAwemeDetailMoreApiResult.getInteract_info().getLiked_count());
                    note.setComments_count(xhsAwemeDetailMoreApiResult.getInteract_info().getComment_count());
                    note.setShared_count(xhsAwemeDetailMoreApiResult.getInteract_info().getShare_count());
                }

                AwemeDetailPlatformResult.AwemeDetail.Note.ShareInfo shareInfo = note.new ShareInfo();
                note.setShare_info(shareInfo);

                if (! CollectionUtils.isEmpty(xhsAwemeDetailMoreApiResult.getImage_list())) {
                    List<AwemeDetailPlatformResult.AwemeDetail.Note.Image> imageList = new ArrayList<>();
                    note.setImages_list(imageList);
                    shareInfo.setImage(xhsAwemeDetailMoreApiResult.getImage_list().get(0).getUrl_default());
                    for (XhsAwemeDetailMoreApiResult.Note.Image image : xhsAwemeDetailMoreApiResult.getImage_list()) {
                        AwemeDetailPlatformResult.AwemeDetail.Note.Image image1 = note.new Image();
                        image1.setFileid(image.getFile_id());
                        image1.setHeight(image.getHeight());
                        image1.setWidth(image.getWidth());
                        image1.setUrl(image.getUrl());
                        image1.setTrace_id(image.getTrace_id());
                        if(! CollectionUtils.isEmpty(image.getInfo_list())){
                            for(XhsAwemeDetailMoreApiResult.Note.Image.CoverInfo infoList : image.getInfo_list()){
                                if(Constant.CRD_WM_WEBP.equals(infoList.getImage_scene())){
                                    image1.setOriginal(infoList.getUrl());
                                }
                            }
                        }
                        if(image.getStream() != null && !CollectionUtils.isEmpty(image.getStream().getH264())){
                            AwemeDetailPlatformResult.AwemeDetail.Note.Image.LivePhoto livePhoto = image1.new LivePhoto();
                            AwemeDetailPlatformResult.AwemeDetail.Note.Image.LivePhoto.Media media = livePhoto.new Media();
                            AwemeDetailPlatformResult.AwemeDetail.Note.Image.LivePhoto.Media.Stream stream = media.new Stream();
                            List<AwemeDetailPlatformResult.AwemeDetail.Note.Image.LivePhoto.Media.Stream.H264> h264List = new ArrayList<>();
                            for (XhsAwemeDetailMoreApiResult.Note.Image.Stream.H264 h264 : image.getStream().getH264()) {
                                AwemeDetailPlatformResult.AwemeDetail.Note.Image.LivePhoto.Media.Stream.H264 h264_1 = stream.new H264();
                                h264_1.setMaster_url(h264.getMaster_url());
                                h264List.add(h264_1);
                            }
                            stream.setH264(h264List);
                            media.setStream(stream);
                            livePhoto.setMedia(media);
                            image1.setLive_photo(livePhoto);
                        }
                        imageList.add(image1);
                    }
                }

                //笔记文案
                if (StringUtils.isNotBlank(xhsAwemeDetailMoreApiResult.getTitle())) {
                    shareInfo.setTitle(xhsAwemeDetailMoreApiResult.getTitle());
                }
                //话题
                List<AwemeDetailPlatformResult.AwemeDetail.Note.HashTagDTO> hashTagDTOList=new ArrayList<>();
                for(XhsAwemeDetailMoreApiResult.Note.Tag tag :xhsAwemeDetailMoreApiResult.getTag_list()){
                    AwemeDetailPlatformResult.AwemeDetail.Note.HashTagDTO hashTag= new AwemeDetailPlatformResult().new AwemeDetail().new Note().new HashTagDTO();
                    hashTag.setId(tag.getId());
                    hashTag.setName(tag.getName());
                    hashTagDTOList.add(hashTag);
                }
                note.setHash_tag(hashTagDTOList);

                noteList.add(note);
                awemeDetail.setNote_list(noteList);
                awemeDetail.setUser(user);

                List<AwemeDetailPlatformResult.AwemeDetail> awemeDetailList = new ArrayList<>();
                awemeDetailList.add(awemeDetail);
                awemeDetailPlatformResult.setData(awemeDetailList);
                awemeDetailPlatformResult.setCode(xhsAwemeDetailMoreApiResultOrg.getCode());
                awemeDetailPlatformResult.setMsg(xhsAwemeDetailMoreApiResultOrg.getMsg());
                result.setData(awemeDetailPlatformResult);
            }
        } catch (Exception e) {
            log.error("SelfAPIUtil.getXhsAwemeDetail2(String) convert error, noteId:{}, e:{}", noteId, e);
        }
        return result;
    }

    public static void main(String[] args) {
        Map<String, Object> params = new HashMap<>();
        params.put("note_id", "66be394f000000001e01e33a");
        params.put("xsec_token", "CBCOLOOEXXcX7-Ug5x6gAsXsmUjQe0XMWAd188KB7duco=");
        //params.put("user_id", "5cfbc3f10000000018023ebb");
        //params.put("cursor", "");

        Map<String, String> headers = new HashMap<>();
        headers.put("Authorization", "Bearer ");

        //String url = "https://open.showsu.cn/api/xhs/user_post";
        String url = "https://open.showsu.cn/api/xhs/note_detail_v2";
        //String url = "https://open.showsu.cn/api/xhs/note_detail";
        String response = HttpClientUtil.postByJson(url,
                headers, JsonUtil.toJson(params), timeout);
        System.out.println(response);
    }
}
